package org.bpm.models
{
	import flash.geom.Point;
	import flash.geom.Rectangle;

	/**
	 * Model of all map nodes.
	 * */
	public class MapNodeModel
	{
		/**
		 * Display area of a node;
		 * */
		public var rect:Rectangle;
		public var id:String;
		public var label:String;
		
		/**
		 * Edges means all transition line label information of the node,
		 * it is defined here in order to follow the standard gpd.xml.
		 * */
		public var edges:Array;
		
		/**
		 * Transition lines.
		 * */
		public var transitions:Array;
		
		/**
		 * Indicates whether this node is processed.
		 * */
		public var isDone:Boolean;
		
		
		/**
		 * Node type, currently includes:
		 * start_state,
		 * end_state,
		 * task_node,
		 * node,
		 * decision,
		 * fork,
		 * join
		 * 
		 * it's IMPORTANT to add a new type as following steps:
		 * 1, create a symbol in Flash Professional and indicate it's linkage class name.
		 * 2, update SWC which generated by Flash Pro.
		 * 3, refer this class name in class org.bpm.utils.UIManifest.
		 * 
		 * 
		 * Regarding to how to create a node view symbol in Flash Professional, please check class
		 * org.bpm.view.MapNode
		 * 
		 * */
		public var type:String;
		
		public var definitionList:XMLList;
		
		public function MapNodeModel(pGPDXML:XMLList, pPDXML:XMLList)
		{
			definitionList = pPDXML;
			
			id = pPDXML.@name;
			label = pPDXML.@name;
			type = String(pPDXML.name()).split("-").join("_");
			isDone = String(pPDXML.@done).toLowerCase() == "true";
			
			
			rect = new Rectangle(Number(pGPDXML.@x), Number(pGPDXML.@y), Number(pGPDXML.@width), Number(pGPDXML.@height));
			
			transitions = new Array();
			
			
			for(var i:int=0,j:int=0;i<pPDXML.children().length();i++){
				var node:XMLList = pPDXML.child(i);
				if(node.name() == "transition"){
					var lineModel:MapLineModel =  new MapLineModel(id,node.@to);
					if(node.@name!=undefined){
						var edgeNode:XMLList = pGPDXML.child(j);
						lineModel.label = node.@name;
						lineModel.labelPosition = new Point(Number(edgeNode.label.@x), Number(edgeNode.label.@y));
						lineModel.isDone = String(node.@done).toLowerCase() == "true";
						lineModel.definitionList = node;
						j++;
					}
					transitions.push(lineModel);
				}
			}
		}
	}
}